package net.alteiar.transformation;

import java.util.HashMap;
import java.util.Map.Entry;

public class SimpleTransformation implements TransformationFunction {

	private final HashMap<TransformationCondition, Integer> transformations;

	public SimpleTransformation() {
		transformations = new HashMap<>();
	}

	public void addTransformation(TransformationCondition cond, int value) {
		transformations.put(cond, value);
	}

	protected int getDefaultValue(int value) {
		return value;
	}

	@Override
	public final int transform(int value) {
		int result = getDefaultValue(value);
		for (Entry<TransformationCondition, Integer> trans : transformations
				.entrySet()) {
			if (trans.getKey().accept(value)) {
				result = trans.getValue();
				break;
			}
		}
		return result;
	}

}
